package com.yyh.collection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.Random;

/**/
public class Test1 {
    public static void main(String[] args) {
        Collection c = new ArrayList();
        System.out.println("c = " + c);//c = []
        //添加元素
        c.add("hello");
        c.add(10);
        c.add(true);
        c.add('a');
        System.out.println("c = " + c);//c = [hello, 10, true, a]
        //删除元素：根据元素删除元素，不能操作索引
        c.remove(10);
        System.out.println("c = " + c);//c = [hello, true, a]
        //修改元素：没有根据索引找到元素并修改的方法
        //查询元素：没有根据索引查询元素
        //将c集合中的元素全部添加到c1集合中
        Collection c1 = new ArrayList();
        System.out.println("c1 = " + c1);//c1 = []
        c1.addAll( c);
        System.out.println("c1 = " + c1);//c1 = [hello, true, a]
        c1.add(3.14);
        c1.add(new Random());
        System.out.println("c1 = " + c1);//c1 = [hello, true, a, 3.14, java.util.Random@74a14482]
        //删除c1集合中所有c集合的元素
        c1.removeAll(c);
        System.out.println("c1 = " + c1);//c1 = [3.14, java.util.Random@74a14482]
        //判断c1集合中是否有3.14的元素
        boolean b = c1.contains(3.14);
        System.out.println("b = " + b);//b = true
        //判断c1集合中是否有c集合的所有元素
        boolean b1 = c1.containsAll(c);
        System.out.println("b1 = " + b1);//b1 = false
        //删除c1集合中所有元素
        c1.clear();
        System.out.println("c1 = " + c1);//c1 = []
        //判断c1集合是否为空
        boolean b2 = c1.isEmpty();
        System.out.println("b2 = " + b2);//b2 = true
        //获取当前集合对象的迭代器对象 ---遍历集合
        Iterator it = c.iterator();
        System.out.println("it = " + it);//it = java.util.ArrayList$Itr@4b2692f0
        //获取当前集合的实际元素的个数
        int size = c.size();
        System.out.println("size = " + size);//size = 3
    }
}
